package com.camunda.workflow.mapper;

import com.mybatisflex.core.BaseMapper;
import com.camunda.workflow.domain.entity.SysRole;
import com.camunda.workflow.domain.entity.SysRoleMenu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SysRoleMapper extends BaseMapper<SysRole> {
    @Delete("<script>DELETE FROM sys_role_menu  " +
            "<where>" +
            "<foreach collection='ids' item='id' open='role_id in (' separator=',' close=')'>#{id}</foreach>" +
            "</where>" +
            "</script>")
    void deleteRoleMenuRelationByRoleIds(@Param("ids") List<String> ids);

    @Insert("<script>" +
            "INSERT INTO sys_role_menu (role_id,menu_id) VALUES " +
            "<foreach collection='roleMenus' item='roleMenu' separator=','>(#{roleMenu.roleId},#{roleMenu.menuId})</foreach>" +
            "</script>")
    void saveRoleMenuRelations(@Param("roleMenus") List<SysRoleMenu> roleMenus);

    @Select("<script>" +
            "select role.* from sys_role role left join sys_user_role ur on role.id = ur.role_id where ur.user_id = #{id} " +
            "</script>")
    SysRole selectRoleByUserId(String id);
}
